package com.hanson;

import com.alibaba.fastjson.JSONArray;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.Expiry;
import com.hanson.common.bean.SkillTimeBean;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

public class Const {

    public static Map<Integer, SkillTimeBean> SKILL_TIME = new LinkedHashMap<>();

    static {
        SKILL_TIME.put(1, new SkillTimeBean(1, "05:00", "5点开始，持续2小时"));
        SKILL_TIME.put(2, new SkillTimeBean(2, "07:00", "7点开始，持续3小时"));
        SKILL_TIME.put(3, new SkillTimeBean(3, "10:00", "10点开始，持续2小时"));
        SKILL_TIME.put(4, new SkillTimeBean(4, "12:00", "12点开始，持续2小时"));
        SKILL_TIME.put(5, new SkillTimeBean(5, "14:00", "14点开始，持续2小时"));
        SKILL_TIME.put(6, new SkillTimeBean(6, "16:00", "16点开始，持续2小时"));
        SKILL_TIME.put(7, new SkillTimeBean(7, "18:00", "18点开始，持续2小时"));
        SKILL_TIME.put(8, new SkillTimeBean(8, "20:00", "20点开始，持续9小时"));
    }

    public static String USER_REDIS_KEY = "UserData::List:%s";
    public static String CATEGORY_REDIS_KEY = "CategoryData::List:%s";
    public static String SLIDE_REDIS_KEY = "SlideData::selectAll";
    public static String NAV_REDIS_KEY = "NavData::selectAll";
    public static String GROUP_GOODS_KEY = "GroupGoodsData:%s";
    /**
     * 商品分享被点击记录map key：点击人 value:分享人
     */
    public static String SHARE_GOODS_KEY = "ShareGoods:%s";
    public static String TASK_KEY = "Task:%s:%s";
    public static String CLIENT_MINI = "miniApp";
    public static String CLIENT_H5 = "h5";

    public static final Cache<String, JSONArray> kuaiDiCache = Caffeine.newBuilder()
            .maximumSize(2000)
            .expireAfter(new Expiry<String, JSONArray>() {
                @Override
                public long expireAfterCreate(String s, JSONArray s2, long l) {
                    return TimeUnit.MINUTES.toNanos(30L);
                }

                @Override
                public long expireAfterUpdate(String s, JSONArray s2, long l, long l1) {
                    return l1;
                }

                @Override
                public long expireAfterRead(String s, JSONArray s2, long l, long l1) {
                    return l1;
                }
            })
            .build();
}
